<?php (!defined('IN_SYSTEM') || !defined('ADMIN_PRE')) && exit('Access Denied!');?>
{admintemplate header}
<div class="box">
 	<div class="heading">
		<h1>商家管理</h1>
		<div class="buttons">
		<a href="{url admin.php?m=shop&mod=list}" {if $mod == 'list'}class="current"{/if}>所有店铺</a>
		<a href="{url admin.php?m=shop&mod=uncheck}" {if $mod == 'uncheck'}class="current"{/if}>待审核店铺</a>
		</div>
	</div>
	
	<div class="main">
	{if !$_REQUEST['f']}
		<div class="search">
			<form name="search" method="get" action="{url admin.php}">
			<input type="hidden" name="m" value="comment" />
			<input type="hidden" name="f" value="index" />
			<input type="hidden" name="mod" value="{$mod}" />
				<fieldset>
					<legend>评论查找</legend>
						关键字：
						<input type="text" name="keyword" size="15" value="{urldecode($keyword)}" />
						<input type="submit" name="s" class="button" value="开始查找" />
						<input type="button" class="button" value="所有评论" onclick="window.location.href='{url admin.php?m=comment&mod=$mod}'" />
						<input type="button" class="button" value="未审核({$no_check_num})" onclick="window.location.href='{url admin.php?m=comment&mod=$mod&check=no}'" />
						<input type="button" class="button" value="已审核" onclick="window.location.href='{url admin.php?m=comment&mod=$mod&check=yes}'" />
				</fieldset>
			</form>
		</div>
	
		<form name="update" method="post" action="{url admin.php?m=comment}">
		<input type="hidden" name="f" id="f" value="" />
			<table class="list" id="list" cellspacing="0">
				<thead>
				<tr>
					<td width="1">
					<input type="checkbox" class="checkbox" value="1" name="chkall" onclick="check_all(this)" />
					</td>
					<td>店铺名</td>
					<td>店主</td>
					<td >联系方式</td>
					<td width="150">日期</td>
					<td width="150">操作</td>
				</tr>
				</thead>
				<tbody>
				{loop $result $row}
				<tr id="row_{$row['shopid']}" {if !$row['ischeck']}class="highlight"{/if}>
					<td class="center"  width="1"><input type="checkbox" name="id[]" value="{$row['shopid']}" class="checkbox" /></td>
					<td><a href="{url admin.php?m=shop&f=edit&id=$row[shopid]}" title="编辑店铺">{$row['shopname']}</a></td>
					<td>{$row['username']}</td>
					<td valign="top">
					{$row['tel']} {$row['shoptel']} {$row['phone']}
					{if $row['qq']}qq:{$row['qq']}{/if}
					</td>
					<td align="center" valign="top">{gdate('Y-m-d H:i', $row['dateline'])}</td>
					<td align="center" valign="top">
					{if ican("shopajax_check")}
					{if $row['status']}
					 <a href="javascript:;" onclick="check_shop({$row['shopid']},false)" id="check_a_{$row['shopid']}">禁止</a>{else}<a href="javascript:;" onclick="check_shop({$row['shopid']},true)" id="check_a_{$row['shopid']}">审核</a>{/if}
					 {/if}
					 {if ican("shopdelete")}
					  | <a href="javascript:;" onclick="delete_shop({$row['shopid']})">删除</a>{/if}
					  {if ican("shopajax_check")}
					| <a href="{url admin.php?m=shop&f=edit&id=$row[shopid]}" title="编辑店铺">编辑</a>
					{/if}
					  </td>
				</tr>
				{/loop}
				<tr>
					<td><input type="checkbox" class="checkbox" value="1" name="chkall" onclick="check_all(this)" /></td>
					<td colspan="5"  class="left">{pager($num,$pagesize,$page,$url)}
					<input type="button" class="button" onclick="do_submit('check',this.form)" value="审核"/>
					<input type="button" class="button" onclick="do_submit('nocheck',this.form)" value="取消审核"/>
					<input type="button" class="button" onclick="do_submit('delete',this.form)" value="删除"/>
					</td>
				</tr>
				</tbody>
			</table>
		</form>
		<script type="text/javascript">
		function check_shop(id) {
			if(!confirm("确定"+$('#check_a_'+id).text()+"该商家?"))return false;
			$.ajax({
				type:'GET',
				url:'admin.php?m=shop&f=ajax_check&id='+id,
				cache:false,
				dataType:'json',
				success:function(message) {
					if (message.type == 'success') {
						if (message.data == 'check') {
							$('#check_a_'+id).text('禁止');
						} else {
							$('#check_a_'+id).text('审核');
						}
					} else {
						alert(message.data);
					}
				}
			});
		}
		function delete_shop(id) {
			if(!confirm("确定删除该商家?"))return false;
			$.ajax({
				type:'GET',
				url:'admin.php?m=shop&f=delete&id='+id,
				cache:false,
				dataType:'json',
				success:function(message) {
					if (message.type == 'success') {
						$("#row_"+id).remove();
					} else {
						alert('系统错误, 请刷新重试');
					}
				}
			});
		}
		</script>
	{/if}

	{if $_REQUEST['f']=='edit'}
	<form name="user_add" method="post" action="{url admin.php?m=shop&f=save}"  enctype="multipart/form-data">
	<input type="hidden" name="shopid" value="{$id}"></input>
	<input type="hidden" id="rid" value="{$result['rid']}" name="rid"/>
    <input type="hidden" name="street1" value="{$result['addr2']}" id="street1"/>
	<table cellspacing="0" class="uc_fa_table">
		<tr>
			<td class="td1">店主姓名：</td>
			<td ><input type="text" name="username" class="input" size="21" value="{$result['username']}" /></td>
			<td  class="td1">店主QQ：</td>
			<td ><input type="text" name="qq" class="input" size="21" value="{$result['qq']}" /></td>
		
		</tr>
		<tr>
			<td class="td1">店主手机：</td>
			<td ><input type="text" name="phone" class="input" value="{$result['phone']}" size="21" /></td>
			<td class="td2">店主电话：</td>
			<td><input type="text" name="tel" class="input" size="21" value="{$result['tel']}" /></td>
		
		</tr>
		<tr>
			<td class="td1">餐厅名称：</td>
			<td colspan="3"><input type="text" name="shopname" class="input" value="{$result['shopname']}" size="57" /></td>
		
		</tr>
		<tr>
			<td class="td1" >经营类型：</td>
			<td colspan="3" >
			<select name="stype" id="stype" >
			{loop $cates $cate}
			<option value="{$cate['cid']}" {if $cate['cid']== $result['cid']}selected{/if}>{$cate['catename']}</option>
			{/loop}
			</select>
			</td>
		</tr>
		<tr>
			<td class="td1" >外卖时间：</td>
			<td colspan="3" >
			从
			<select name="opentime" id="opentime">
			{loop $worktime1 $k $w}
			<option value="{$k}" {if $k == $result['opentime']}selected{/if}>{$w}</option>
			{/loop}
			</select>
			到
			<select name="closetime" id="closetime">
			{loop $worktime2 $k $w}
			<option value="{$k}" {if $k == $result['closetime']}selected{/if}>{$w}</option>
			{/if}
			</select>
			<input type="checkbox" value="1" {if $result['sat']}checked{/if} name="res1">周六休息</input>
			<input type="checkbox" value="1" {if $result['sun']}checked{/if} name="res2">周日休息</input>
			</td>
		</tr>
		<tr>
			<td class="td1">订餐电话：</td>
			<td  colspan="3"><input type="text" name="tel" class="input" value="{$result['tel']}" size="57" /></td>
		
		</tr>
		<tr>
			<td  class="td1">起送价：</td>
			<td  colspan="3"><input type="text" name="minprice" class="input" size="57" value="{$result['minprice']}" /></td>
		</tr>
		<tr>
			<td class="td1" >所属地区：</td>
			<td colspan="3" >{$region}</td>
		</tr>
		<tr>
			<td class="td1">详细地址：</td>
			<td colspan="3"><span id="address">{$result['addr2']}</span><input type="text" name="addr1" class="input" size="31" value="{$result['addr1']}" /></td>
		</tr>
		
		<tr>
			<td class="td1">公交线路：</td>
			<td colspan="3"><input type="text" name="bus" class="input" size="57" value="{$result['bus']}" /></td>
		</tr>
		<tr>
			<td class="td1" valign="top">主营描述：</td>
			<td colspan="3"><textarea name="description" cols="56" rols="4">{$result['description']}</textarea>
		</tr>
		<tr>
			<td class="td1" valign="top">餐厅承诺：</td>
			<td colspan="3"><textarea name="chengnuo" cols="56" rols="4">{$result['chengnuo']}</textarea>
		</tr>
		<tr>
			<td class="td1" valign="top">餐厅特点：</td>
			<td colspan="3"><textarea name="tedian" cols="56" rols="4">{$result['tedian']}</textarea>
		</tr>
		<tr class="bg2"><td class="td1"></td><td colspan="3"><input type="submit" class="button" value="保存" /> </td></tr>
	</table>
	</form>
	<script type="text/javascript">
			function region(obj,le){
				var val=$(obj).val();
				if(val<1 && le>0 && $("#level"+(le-1)).val() >0){
					$("#rid").val($("#level"+(le-1)).val());
				}else{
					$("#rid").val(val);
				}
				var ht='';
				var lev=le;
				if(val<1){
					lev=lev-1;
					if(lev<1){
						$('#address').html("");
						$('#street1').val("");
					}
				}
				for(var i=1;i<=lev;i++){
						ht=ht+$("#level"+i).find("option:selected").text();
						$('#address').html(ht);
						$('#street1').val(ht);
				}
				if($(obj).val()<1){
					$('#level'+(le+1)).remove();
					$('#level'+(le+2)).remove();
					$('#level'+(le+3)).remove();
					return ;
				}
				$.getJSON('home.php?m=addr&f=ajax&id='+$(obj).val()+'&tm='+Math.random(),'',function(data){
					if(data.status==true){
						$('#level'+(le+1)).remove();
						$('#level'+(le+2)).remove();
						$('#level'+(le+3)).remove();
						$(data.data).insertAfter($('#level'+le));
					}else{
					}
					});
			}
			</script>
	{/if}
	</div>
</div>
{admintemplate footer}